package com.jz.digital.view;

import android.app.Activity;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jz.digital.R;
import com.jz.digital.utils.DipPixelUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 使用说明：这个自定义的公共的标题栏类提供了丰富的标题栏的方法，建议尽量使用，用来替代重复复杂的标题栏
 * 用法：
 * 只需要在xml布局文件中添加 common_title 标题栏就行了：
 * <p/>
 * 案例如下：
 * <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 * xmlns:app="http://schemas.android.com/apk/res-auto"
 * android:layout_width="match_parent"
 * android:layout_height="match_parent"
 * android:background="#F5F5F5"
 * android:orientation="vertical">
 * <p/>
 * // 标题栏
 * <include layout="@layout/common_title" />
 * <p/>
 * </LinearLayout>
 */

/**
 * @author: lyw
 * @package: com.ido.veryfitpro.util
 * @description: ${TODO}{自定义的公共的标题栏类}
 * @date: 2016/5/18 09:13
 */
public class CommonTitleBarHelper implements View.OnClickListener {

    public static final int leftId = R.id.leftId; // 左边返回图片id
    public static final int titleId = R.id.titleId;
    public static final int rightId = R.id.rightId;
    public static final int rightImgId = R.id.rightImgId; // 右边第一个image id
    public static final int leftImgId = R.id.leftImgId; // 左边图片Id
    public static final int rightStrId = R.id.rightStrId; // 右边文字id
    public static final int leftStrId = R.id.leftStrId;//左边文字ID
    public static final int DEFAULT_LEFT_IMAGE = 0;
    public static final int NO_LEFT_IMAGE = -1;
    public static final int DEFAULT_MID_TITLECOLOR = 0;
    public static final int DEFAULT_MID_TITLESIZE = 0;
    public static final int DEFAULT_RIGHT_IMAGE = 0;
    public static int defaultTextSize = 18;

    public static final int LOACTION_LEFT = 0;
    public static final int LOACTION_MID = 1;
    public static final int LOACTION_RIGHT = 2;
    public static final int LOACTION_ALL = 3;
    Activity activity;


    //中间子控件的集合
    List<View> mids = new ArrayList<View>();

    //右边子控件的集合
    List<View> rights = new ArrayList<View>();


    //左边子控件的集合
    List<View> lefts = new ArrayList<View>();
    /**
     * 带左边的TextViw的布局
     */
    public static final int STYLE_LEFT_RIGHT_TEXT = 10;
    /**
     * 默认的布局
     * 左边一个ImageView,中间一个TextView
     */
    public static final int STYLE_DEFAULT = 0;


    /**
     * 带右边的ImageView的布局
     * 左边一个ImageView,中间一个TextView,右边一个ImageView
     */
    public static final int STYLE_RIGHT_IMG = 1;
    /**
     * 带右边的TextView的布局
     * 左边一个ImageView,中间一个TextView,右边一个TextView
     */
    public static final int STYLE_RIGHT_TEXT = 2;

    /**
     * 左边、中间、右边都带有一个TextView
     */
    public static final int STYLE_ALL_TEXT = 3;

    /**
     * 带左边的ImageView和TextViw的布局
     */
    public static final int STYLE_LEFT_IMG_TXT_RIGHT_TEXT = 4;

    /**
     * 左边默认图片
     */
    private static final int DEFAULT_LEFT_IMG_RES = R.mipmap.arrow_left;

    /**
     * 右边默认图片
     */
    private static final int DEFAULT_RIGHT_IMG_RES = R.mipmap.icon_save;

    /**
     * 标题栏默认背景
     */
    private static final int DEFAULT_BG_RES = Color.TRANSPARENT;

    /**
     * 背景资源
     */
    private int titleBgRes;

    public boolean isHasBar() {
        return hasBar;
    }

    public void setHasBar(boolean hasBar) {
        this.hasBar = hasBar;
    }

    /**
     * 判断该Activity是否设置了头部
     */
    private boolean hasBar = true;
    private ImageView rightImg;
    private float rightPadding = 10;
    private float leftPadding = DipPixelUtil.dip2px(16);

    /**
     * 是否正在显示取消按钮
     */
    private boolean isOnlyCancelShowing = false;

    private View.OnClickListener mOnLeftClickListener = null;

    /**
     * 左侧文字点击事件
     */
    private View.OnClickListener mOnLeftTextClickListener = null;

    /**
     * 默认的布局是STYLE_DEFAUL
     *
     * @param activity
     * @see #STYLE_DEFAULT
     * @see #STYLE_RIGHT_IMG
     * @see #STYLE_RIGHT_TEXT
     */
    public void init(Activity activity) {
        this.activity = activity;
        rightPadding = activity.getResources().getDimension(R.dimen.sw_dp_16);
        leftPadding = activity.getResources().getDimension(R.dimen.sw_dp_16);
        hasBar = activity.findViewById(R.id.layout_left) != null;
        if (hasBar) {
            initLayout();
        }

    }

    private CommonTitleBarHelper initLayout() {
        return initLayout(STYLE_DEFAULT);
    }

    /**
     * 设置标题字符串
     *
     * @param res
     * @return
     */
    public CommonTitleBarHelper setTitle(int res) {
        return setTitle(activity.getResources().getString(res));
    }

    /**
     * 设置标题字符串
     *
     * @param text
     * @return
     */
    public CommonTitleBarHelper setTitle(String text) {
        if (hasBar) {
            ((TextView) activity.findViewById(titleId)).setText(text);
        }

        return this;
    }

    /**
     * 设置标题颜色
     */
    public void setTitleColor(int color) {
        if (hasBar) {
            ((TextView) activity.findViewById(titleId)).setTextColor(color);
        }
    }

    /**
     * 设置右边图片资源
     *
     * @param res
     * @return
     */
    public CommonTitleBarHelper setRightImg(int res) {
        activity.findViewById(rightImgId).setBackgroundResource(res);
        activity.findViewById(rightImgId).setBackgroundTintList(ColorStateList.valueOf(Color.WHITE));
        return this;
    }

    public ImageView getRightImg(){
        return activity.findViewById(rightImgId);
    }

    /**
     * 设置右边图片资源背景
     *
     * @param stateList
     * @return
     */
    public CommonTitleBarHelper setRightImgTint(ColorStateList stateList) {
        if (activity.findViewById(rightImgId)==null)
            return null;
        activity.findViewById(rightImgId).setBackgroundTintList(stateList);
        return this;
    }

    public CommonTitleBarHelper setRightVisible(boolean visible) {
        if (hasBar) {
            LinearLayout layout = getTitleLayoutRight(activity);
            if (layout != null) {
                layout.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
            }
        }
        return this;
    }

    /**
     * 设置左边图片资源
     *
     * @param res
     * @return
     */
    public CommonTitleBarHelper setLeftImg(int res) {

        activity.findViewById(leftImgId).setBackgroundResource(res);
        return this;
    }

    /**
     * 设置左边图片资源背景
     *
     * @param stateList
     * @return
     */
    public CommonTitleBarHelper setLeftImgTint(ColorStateList stateList) {
        activity.findViewById(leftImgId).setBackgroundTintList(stateList);
        return this;
    }

    /**
     * 设置左边图片是否可见
     *
     * @param visible
     * @return
     */
    public CommonTitleBarHelper setLeftImgVisible(boolean visible) {
        activity.findViewById(leftImgId).setVisibility(visible ? View.VISIBLE : View.GONE);
        return this;
    }

    public CommonTitleBarHelper switchLeftImgAndTextVisibility(boolean showImg) {
        setLeftImgVisible(showImg);
        setLeftTextVisible(!showImg);
        checkLeftVisible();
        return this;
    }

    private void checkLeftVisible() {
        View leftTextView = activity.findViewById(leftStrId);
        View leftImgView = activity.findViewById(leftImgId);
        isOnlyCancelShowing = leftTextView != null && leftTextView.getVisibility() == View.VISIBLE && (leftImgView == null || leftImgView.getVisibility() != View.VISIBLE);
    }

    /**
     * 设置左边文字是否可见
     *
     * @param visible
     * @return
     */
    public CommonTitleBarHelper setLeftTextVisible(boolean visible) {
        if (hasBar) {
            View view = activity.findViewById(leftStrId);
            if (view != null) {
                view.setVisibility(visible ? View.VISIBLE : View.GONE);
            }
        }
        return this;
    }

    public CommonTitleBarHelper setRightEnable(boolean enabled) {
        if (hasBar) {
            View view = activity.findViewById(rightStrId);
            if (view != null) {
                view.setEnabled(enabled);
            }
            getTitleLayoutRight(activity).setEnabled(enabled);
        }
        return this;
    }


    /**
     * 设置右边图片文字
     *
     * @param res
     * @return
     */
    public CommonTitleBarHelper setRightText(int res) {
        if (hasBar) {
            ((TextView) activity.findViewById(rightStrId)).setText(res);
        }
        return this;
    }

    /**
     * 设置右边图片文字
     *
     * @return
     */
    public CommonTitleBarHelper setRightText(String title) {
        if (hasBar) {
            ((TextView) activity.findViewById(rightStrId)).setText(title);
        }
        return this;
    }

    /**
     * 设置右边图片文字
     *
     * @return
     */
    public CommonTitleBarHelper setRightHintText(String hint,int hintColor) {
        if (hasBar) {
            TextView rightText = ((TextView) activity.findViewById(rightStrId));
            rightText.setHint(hint);
            rightText.setHintTextColor(hintColor);
        }
        return this;
    }

    /**
     * 设置右边图片文字颜色
     *
     * @param res
     * @return
     */
    public CommonTitleBarHelper setRightTextColor(int res) {
        if (hasBar) {
            ((TextView) activity.findViewById(rightStrId)).setTextColor(res);
        }
        return this;
    }

    /**
     * 设置右边文字颜色selector
     *
     * @param res
     * @return
     */
    public CommonTitleBarHelper setRightTextColor(ColorStateList res) {
        if (hasBar) {
            ((TextView) activity.findViewById(rightStrId)).setTextColor(res);
        }
        return this;
    }

    /**
     * 设置右边图片文字
     *
     * @param res
     * @return
     */
    public CommonTitleBarHelper setLeftText(int res) {
        if (hasBar) {
            ((TextView) activity.findViewById(leftStrId)).setText(res);
        }
        return this;
    }

    /**
     * 设置右边图片文字
     *
     * @return
     */
    public CommonTitleBarHelper setLeftText(String title) {
        if (hasBar) {
            ((TextView) activity.findViewById(leftStrId)).setText(title);
        }
        return this;
    }

    /**
     * 设置右边图片文字颜色
     *
     * @param res
     * @return
     */
    public CommonTitleBarHelper setLeftTextColor(int res) {
        if (hasBar) {
            ((TextView) activity.findViewById(leftStrId)).setTextColor(res);
        }
        return this;
    }

    /**
     * 设置右边图片资源
     *
     * @param l 监听
     * @return
     */
    public CommonTitleBarHelper setRightOnClick(View.OnClickListener l) {
        if (hasBar && currentStyle != STYLE_DEFAULT) {
            getTitleLayoutRight(activity).setOnClickListener(l);
        }
        return this;
    }

    /**
     * 设置右边图片资源
     *
     * @param l 监听
     * @return
     */
    public CommonTitleBarHelper setLeftOnClick(View.OnClickListener l) {
        if (hasBar) {
            mOnLeftClickListener = l;
        }
        return this;
    }

    public CommonTitleBarHelper setLeftTextOnClick(View.OnClickListener l) {
        if (hasBar) {
            mOnLeftTextClickListener = l;
        }
        return this;
    }

    private int currentStyle = STYLE_DEFAULT;

    /**
     * @param style 标题栏布局类型
     * @return
     * @see #STYLE_DEFAULT
     * @see #STYLE_RIGHT_IMG
     * @see #STYLE_RIGHT_TEXT
     */
    public CommonTitleBarHelper initLayout(int style) {
        rights.clear();
        lefts.clear();
        mids.clear();
        currentStyle = style;
        switch (style) {
            case STYLE_DEFAULT:
                addLeftImageView();
                addMidTextView();
                break;
            case STYLE_RIGHT_IMG:
                addLeftImageView();
                addMidTextView();
                addRightImageView();
                break;
            case STYLE_RIGHT_TEXT:
                addLeftImageView();
                addMidTextView();
                addRightTextView();
                break;
            case STYLE_ALL_TEXT:
                addLeftTextView();
                addMidTextView();
                addRightTextView();
                break;
            case STYLE_LEFT_IMG_TXT_RIGHT_TEXT:
                addLeftImageView();
                addLeftTextView();
                addMidTextView();
                addRightTextView();
                break;
        }
        initBar();
        return this;
    }

    public CommonTitleBarHelper setRightTextPadding(int rightPadding) {
        this.rightPadding = rightPadding;
        return this;
    }

    /**
     * 方法1：得到标题左布局
     *
     * @param activity
     * @return
     */
    public LinearLayout getTitleLayoutLeft(Activity activity) {
        return findViewById(activity, R.id.layout_left);
    }

    private LinearLayout findViewById(Activity activity, int res) {
        LinearLayout linearLayout = activity.findViewById(res);
        linearLayout.setVisibility(View.VISIBLE);
        return linearLayout;
    }

    /**
     * 方法2：得到标题中间布局
     *
     * @param activity
     * @return
     */
    public LinearLayout getTitleLayoutMid(Activity activity) {
        return findViewById(activity, R.id.layout_mid);
    }

    /**
     * 方法3：得到标题右布局
     *
     * @param activity
     * @return
     * @ TODO 注意 调用该方法会将右布局显示出来
     */
    public LinearLayout getTitleLayoutRight(Activity activity) {
        return findViewById(activity, R.id.layout_right);
    }

    /**
     * 方法4：得到标题整体布局
     *
     * @param activity
     * @return
     */
    public LinearLayout getTitleLayoutAll(Activity activity) {
        return findViewById(activity, R.id.layout_parent);
    }

    /**
     * 设置左边图片颜色
     */
    public void setLeftImageColorStateList(Activity activity, ColorStateList stateList) {
        if (stateList == null || activity == null) return;
        ImageView imageView = activity.findViewById(leftImgId);
        if (imageView != null) imageView.setImageTintList(stateList);
    }

    /**
     * 方法8：设置标题的背景色
     *
     * @param activity
     * @param bgcolor
     * @param location:0:左边布局 1:中间布局  2:右边布局  3:整体布局
     * @see #LOACTION_LEFT
     * @see #LOACTION_MID
     * @see #LOACTION_RIGHT
     * @see #LOACTION_ALL
     */
    public void setTitleLayoutBgcolor(Activity activity, int bgcolor, int location) {
        LinearLayout layout = null;
        switch (location) {
            case LOACTION_LEFT:
                layout = getTitleLayoutLeft(activity);
                break;
            case LOACTION_MID:
                layout = getTitleLayoutMid(activity);
                break;
            case LOACTION_RIGHT:
                layout = getTitleLayoutRight(activity);
                break;
            case LOACTION_ALL:
                layout = getTitleLayoutAll(activity);
                break;
            default:
                layout = getTitleLayoutAll(activity);
                break;
        }
        layout.setBackgroundColor(bgcolor);
    }

    /**
     * 方法9：设置整个标题栏的背景色
     *
     * @param activity
     * @param bgcolor
     */
    public void setTitleLayoutAllBgcolor(Activity activity, int bgcolor) {
        setTitleLayoutBgcolor(activity, bgcolor, LOACTION_ALL);
    }

    /**
     * 方法10：标题栏最基础添加方法
     *
     * @param activity
     * @param lefts
     * @param mids
     * @param rights
     */
    private void addTitle(Activity activity, List<View> lefts,
                          List<View> mids, List<View> rights) {

        LinearLayout leftLayout = getTitleLayoutLeft(activity);
        LinearLayout midLayout = getTitleLayoutMid(activity);
        LinearLayout rightLayout = getTitleLayoutRight(activity);
        leftLayout.removeAllViews();
        midLayout.removeAllViews();
        rightLayout.removeAllViews();
        if (lefts != null) {
            for (View view : lefts) {
                leftLayout.addView(view);
            }
        }
        if (mids != null) {
            for (View view : mids) {
                midLayout.addView(view);
            }
        }
        if (rights != null) {
            for (View view : rights) {
                rightLayout.addView(view);
            }
        }
        setBarBackground(DEFAULT_BG_RES);
    }

    /**
     * 方法10：标题栏最基础添加方法
     */
    private void initBar() {
        LinearLayout leftLayout = getTitleLayoutLeft(activity);
        LinearLayout midLayout = getTitleLayoutMid(activity);
        LinearLayout rightLayout = getTitleLayoutRight(activity);
        leftLayout.removeAllViews();
        midLayout.removeAllViews();
        rightLayout.removeAllViews();
        if (lefts != null) {
            for (View view : lefts) {
                leftLayout.addView(view);
            }
        }
        if (mids != null) {
            for (View view : mids) {
                midLayout.addView(view);
            }
        }
        if (rights != null) {
            for (View view : rights) {
                rightLayout.addView(view);
            }
        }
        if (titleBgRes == 0) {
            titleBgRes = DEFAULT_BG_RES;
        }
        setBarBackground(titleBgRes);
        //标题颜色
        setTitleColor(Color.BLACK);
        //返回按钮颜色
        if (currentStyle != STYLE_ALL_TEXT){
            setLeftImgTint(ColorStateList.valueOf(Color.BLACK));
        }
        checkLeftVisible();
        getTitleLayoutLeft(activity).setOnClickListener(this);
    }

    private ImageButton createImageButton(int id, int imageResource) {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        params.setMargins(20, 0, 0, 0);
        params.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;

        // 返回按钮
        ImageButton imageButton = new ImageButton(activity);
        imageButton.setLayoutParams(params);
        imageButton.setId(id);
        imageButton.setPadding(0, 0, 0, 0);
        if (imageResource == 0) {
            imageButton.setImageResource(DEFAULT_LEFT_IMG_RES);
        } else if (imageResource == -1) {

        } else {
            imageButton.setImageResource(imageResource);
        }
        imageButton.setBackgroundColor(Color.TRANSPARENT);
        return imageButton;
    }

    /*public void startRightAnimation() {
        setRightImg(R.mipmap.refresh);
        Animation rotateAnimation = AnimationUtils.loadAnimation(activity, R.anim.progress_drawable);
        rightImg = activity.findViewById(rightImgId);
        rightImg.startWaveShiftAnimation(rotateAnimation);
    }*/

    /**
     * 设置右边图片点击前添加动画
     *
     * @param rightListener 右边监听
     * @param isAnimaton    是否执行动画
     * @param isDelay       是否延迟执行监听
     */
    public CommonTitleBarHelper setRightAnimation(final View.OnClickListener rightListener, final boolean isAnimaton, final boolean isDelay) {


        rightImg = activity.findViewById(rightImgId);
        rightImg.setOnClickListener(view -> {
            if (rightListener == null) {
                return;
            }
            rightListener.onClick(view);
        });
        return this;
    }

    /**
     * 设置右边图片点击前添加动画
     *
     * @param rightListener       右边监听
     * @param isAnimation         是否执行动画
     * @param shouldConnectDevice 是否延迟执行监听
     */
    public CommonTitleBarHelper setRightAnimationClick(final View.OnClickListener rightListener, final boolean isAnimation, final boolean shouldConnectDevice) {
        rightImg = activity.findViewById(rightImgId);
        rightImg.setOnClickListener(view -> {
            if (rightListener == null) {
                return;
            }
            rightListener.onClick(view);

        });
        return this;
    }

    public boolean rightAnimation = true;

    private boolean isAnimation(boolean isAnimation) {
        return isAnimation && rightAnimation;
    }


    private boolean isDelay = false;


    /**
     * 关闭右边的动画
     */
    public void closeAnimation() {
        rightImg = activity.findViewById(rightImgId);
        if (rightImg != null) {
            rightImg.clearAnimation();
            rightImg.setBackgroundResource(DEFAULT_RIGHT_IMG_RES);
        }
//        if (rotateAnimation != null) {
//            rotateAnimation.cancel();
//            rotateAnimation = null;
//        }
    }

    /**
     * ：设置整个标题栏的背景
     *
     * @param backgroundRes 背景资源文件
     */
    public CommonTitleBarHelper setBarBackground(int backgroundRes) {
        titleBgRes = backgroundRes;
        LinearLayout layout = findViewById(activity, R.id.layout_parent);
        if (layout != null) {
            try {
                layout.setBackgroundResource(backgroundRes);
            }catch (Exception e){
                layout.setBackgroundColor(backgroundRes);
            }
        }
        return this;
    }

    private ImageView createImageView(Activity activity, int id, int leftImage, int defaltRes) {
        return createImageView(activity, id, leftImage, defaltRes, 0, 0, 0, 0);
    }

    private ImageView createImageView(Activity activity, int id, int leftImage, int defaltRes, int padleft, int padtop, int padright, int padbottom) {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        ImageView leftImg = new ImageView(activity);
        leftImg.setLayoutParams(params);
        leftImg.setId(id);
        leftImg.setPadding(padleft, padtop, padright, padbottom);
        if (leftImage == DEFAULT_LEFT_IMAGE) {
            leftImg.setBackgroundResource(defaltRes);
        } else {
            leftImg.setBackgroundResource(leftImage);
        }
        return leftImg;
    }

    private TextView createTextView(Activity activity, String title, int textSize, int textColor, int id) {
        return createTextView(title, textSize, textColor, id);
    }

    private TextView createTextView(String title, float textSize, int textColor, int id) {
        return createTextView(title, textSize, textColor, id, 0, 0, true);
    }

    private TextView createTextView(String title, float textSize, int textColor, int id, float paddingLeft, float paddingRight, boolean isBold) {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        // 返回标题
        TextView textView = new TextView(activity);
        textView.getPaint().setFakeBoldText(isBold);
        textView.setText(title);
        textView.setId(id);
//        textView.setTypeface(Typeface.createFromAsset(activity.getAssets(), "font/metrictest_medium.otf"));
//        textView.setMaxEms(9);
        textView.setSingleLine(true);
        textView.setPadding((int) paddingLeft, 0, (int) paddingRight, 0);
        textView.setEllipsize(TextUtils.TruncateAt.END);
        textView.setLayoutParams(params);
        if (textSize == 0) {
            textView.setTextSize(defaultTextSize);
        } else {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        }
        if (textColor == 0) {
            textView.setTextColor(activity.getResources().getColor(
                    R.color.black));
        } else {
            textView.setTextColor(activity.getResources().getColor(textColor));
        }
        return textView;
    }


    @Override
    public void onClick(View v) {
        if (isOnlyCancelShowing) {
            if (mOnLeftTextClickListener != null) {
                mOnLeftTextClickListener.onClick(v);
            }
        } else {
            if (mOnLeftClickListener != null) {
                mOnLeftClickListener.onClick(v);
            }
        }
    }

    static class ClickFinished implements View.OnClickListener {
        private Activity activity;

        public ClickFinished(Activity activity) {
            this.activity = activity;
        }

        @Override
        public void onClick(View v) {
            activity.finish();
        }
    }

    /**
     * 左边默认的监听是调用finished方法
     */
    private void addLeftImageView() {
        // 左侧的取消按钮
        ImageView leftImg = createImageView(activity, leftImgId, DEFAULT_LEFT_IMG_RES, DEFAULT_LEFT_IMG_RES);
        mOnLeftClickListener = new ClickFinished(activity);
        lefts.add(leftImg);
    }

    private void addRightImageView() {
        // 左侧的取消按钮
        ImageView leftImg = createImageView(activity, rightImgId, DEFAULT_RIGHT_IMG_RES, DEFAULT_RIGHT_IMG_RES, 10, 10, 10, 10);
        rights.add(leftImg);
    }

    private void addMidTextView() {
        TextView midTitle = createTextView("", activity.getResources().getDimension(R.dimen.size18sp), R.color.color_282C2F, titleId);
        mids.add(midTitle);
    }

    private void addRightTextView() {
        TextView midTitle = createTextView("", activity.getResources().getDimension(R.dimen.size16sp), R.color.white, rightStrId, 0, rightPadding, false);
        rights.add(midTitle);
    }

    private void addLeftTextView() {
        TextView leftTitle = createTextView("", activity.getResources().getDimension(R.dimen.size16sp), R.color.white, leftStrId, leftPadding, 0, false);
        lefts.add(leftTitle);
    }


    public class CloseAnimator {
        private ImageView view;

        public void close() {
            if (view != null) {
                view.clearAnimation();
                view.setImageResource(R.mipmap.icon_save);
            }

        }
    }
}
